Skip to content

Conversation

@flovent
Copy link
Contributor

@flovent flovent commented Sep 5, 2025

Closes #156157

@llvmbot
Copy link
Member

llvmbot commented Sep 5, 2025

@llvm/pr-subscribers-clang-tidy

Author: None (flovent)

Changes

Closes #156157


Full diff: https://github.com/llvm/llvm-project/pull/157123.diff

16 Files Affected:

  • (modified) clang-tools-extra/clang-tidy/.clang-tidy (-1)
  • (modified) clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp (+1-1)
  • (modified) clang-tools-extra/clang-tidy/NoLintDirectiveHandler.cpp (+1-1)
  • (modified) clang-tools-extra/clang-tidy/abseil/UpgradeDurationConversionsCheck.cpp (+1-1)
  • (modified) clang-tools-extra/clang-tidy/bugprone/SignalHandlerCheck.cpp (+1-1)
  • (modified) clang-tools-extra/clang-tidy/bugprone/SwappedArgumentsCheck.cpp (+1-1)
  • (modified) clang-tools-extra/clang-tidy/bugprone/UseAfterMoveCheck.cpp (+2-2)
  • (modified) clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp (+2-2)
  • (modified) clang-tools-extra/clang-tidy/google/UpgradeGoogletestCaseCheck.cpp (+1-1)
  • (modified) clang-tools-extra/clang-tidy/modernize/AvoidBindCheck.cpp (+1-1)
  • (modified) clang-tools-extra/clang-tidy/modernize/DeprecatedHeadersCheck.cpp (+1-1)
  • (modified) clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp (+1-1)
  • (modified) clang-tools-extra/clang-tidy/performance/TypePromotionInMathFnCheck.cpp (+1-1)
  • (modified) clang-tools-extra/clang-tidy/utils/ExprSequence.cpp (+2-2)
  • (modified) clang-tools-extra/clang-tidy/utils/FileExtensionsUtils.cpp (+1-1)
  • (modified) clang-tools-extra/clang-tidy/utils/NamespaceAliaser.cpp (+2-2)
diff --git a/clang-tools-extra/clang-tidy/.clang-tidy b/clang-tools-extra/clang-tidy/.clang-tidy
index 0e33364442e76..6bb526c50ff71 100644
--- a/clang-tools-extra/clang-tidy/.clang-tidy
+++ b/clang-tools-extra/clang-tidy/.clang-tidy
@@ -22,7 +22,6 @@ Checks: >
   readability-*,
   -readability-avoid-nested-conditional-operator,
   -readability-braces-around-statements,
-  -readability-container-contains,
   -readability-convert-member-functions-to-static,
   -readability-else-after-return,
   -readability-function-cognitive-complexity,
diff --git a/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp b/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp
index 5e705f720c86e..487e5e299d132 100644
--- a/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp
+++ b/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp
@@ -35,7 +35,7 @@ class ExpandModularHeadersPPCallbacks::FileRecorder {
                          const SrcMgr::ContentCache &ContentCache,
                          llvm::vfs::InMemoryFileSystem &InMemoryFs) {
     // Return if we are not interested in the contents of this file.
-    if (!FilesToRecord.count(File))
+    if (!FilesToRecord.contains(File))
       return;
 
     // FIXME: Why is this happening? We might be losing contents here.
diff --git a/clang-tools-extra/clang-tidy/NoLintDirectiveHandler.cpp b/clang-tools-extra/clang-tidy/NoLintDirectiveHandler.cpp
index ed03b456f4954..a8c978901b551 100644
--- a/clang-tools-extra/clang-tidy/NoLintDirectiveHandler.cpp
+++ b/clang-tools-extra/clang-tidy/NoLintDirectiveHandler.cpp
@@ -349,7 +349,7 @@ bool NoLintDirectiveHandler::Impl::diagHasNoLint(
     return false;
 
   // Do we have cached NOLINT block locations for this file?
-  if (Cache.count(*FileName) == 0)
+  if (!Cache.contains(*FileName))
     // Warning: heavy operation - need to read entire file.
     generateCache(SrcMgr, *FileName, File, *Buffer, NoLintErrors);
 
diff --git a/clang-tools-extra/clang-tidy/abseil/UpgradeDurationConversionsCheck.cpp b/clang-tools-extra/clang-tidy/abseil/UpgradeDurationConversionsCheck.cpp
index 8e27e8e3e0c2b..b2eddf67edb3f 100644
--- a/clang-tools-extra/clang-tidy/abseil/UpgradeDurationConversionsCheck.cpp
+++ b/clang-tools-extra/clang-tidy/abseil/UpgradeDurationConversionsCheck.cpp
@@ -126,7 +126,7 @@ void UpgradeDurationConversionsCheck::check(
 
   if (!match(isInTemplateInstantiation(), *OuterExpr, *Result.Context)
            .empty()) {
-    if (MatchedTemplateLocations.count(Loc) == 0) {
+    if (!MatchedTemplateLocations.contains(Loc)) {
       // For each location matched in a template instantiation, we check if the
       // location can also be found in `MatchedTemplateLocations`. If it is not
       // found, that means the expression did not create a match without the
diff --git a/clang-tools-extra/clang-tidy/bugprone/SignalHandlerCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/SignalHandlerCheck.cpp
index d5cbb847eea98..fa38f5e07f832 100644
--- a/clang-tools-extra/clang-tidy/bugprone/SignalHandlerCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/SignalHandlerCheck.cpp
@@ -525,7 +525,7 @@ bool SignalHandlerCheck::isStandardFunctionAsyncSafe(
   if (!FD->isInStdNamespace() && !FD->isGlobal())
     return false;
 
-  if (ConformingFunctions.count(II->getName()))
+  if (ConformingFunctions.contains(II->getName()))
     return true;
 
   return false;
diff --git a/clang-tools-extra/clang-tidy/bugprone/SwappedArgumentsCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/SwappedArgumentsCheck.cpp
index 8989444dde130..7fdb67e9a7cd9 100644
--- a/clang-tools-extra/clang-tidy/bugprone/SwappedArgumentsCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/SwappedArgumentsCheck.cpp
@@ -91,7 +91,7 @@ void SwappedArgumentsCheck::check(const MatchFinder::MatchResult &Result) {
 
     // Only need to check RHS, as LHS has already been covered. We don't want to
     // emit two warnings for a single argument.
-    if (UsedArgs.count(RHS))
+    if (UsedArgs.contains(RHS))
       continue;
 
     const auto *LHSCast = dyn_cast<ImplicitCastExpr>(ignoreNoOpCasts(LHS));
diff --git a/clang-tools-extra/clang-tidy/bugprone/UseAfterMoveCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/UseAfterMoveCheck.cpp
index 1bcacf96a4129..f9906ebf6ea26 100644
--- a/clang-tools-extra/clang-tidy/bugprone/UseAfterMoveCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/UseAfterMoveCheck.cpp
@@ -148,7 +148,7 @@ UseAfterMoveFinder::find(Stmt *CodeBlock, const Expr *MovingCall,
 std::optional<UseAfterMove>
 UseAfterMoveFinder::findInternal(const CFGBlock *Block, const Expr *MovingCall,
                                  const ValueDecl *MovedVariable) {
-  if (Visited.count(Block))
+  if (Visited.contains(Block))
     return std::nullopt;
 
   // Mark the block as visited (except if this is the block containing the
@@ -232,7 +232,7 @@ void UseAfterMoveFinder::getUsesAndReinits(
   // All references to the variable that aren't reinitializations are uses.
   Uses->clear();
   for (const DeclRefExpr *DeclRef : DeclRefs) {
-    if (!ReinitDeclRefs.count(DeclRef))
+    if (!ReinitDeclRefs.contains(DeclRef))
       Uses->push_back(DeclRef);
   }
 
diff --git a/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp b/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
index e6e79f0f0342a..a79c5281d6054 100644
--- a/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
+++ b/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
@@ -99,7 +99,7 @@ toCommaSeparatedString(const R &OrderedDecls,
                        const SmallPtrSetImpl<const T *> &DeclsToInit) {
   SmallVector<StringRef, 16> Names;
   for (const T *Decl : OrderedDecls) {
-    if (DeclsToInit.count(Decl))
+    if (DeclsToInit.contains(Decl))
       Names.emplace_back(getName(Decl));
   }
   return llvm::join(Names.begin(), Names.end(), ", ");
@@ -501,7 +501,7 @@ void ProTypeMemberInitCheck::checkMissingMemberInitializer(
   AnyMemberHasInitPerUnion = false;
   forEachFieldWithFilter(ClassDecl, ClassDecl.fields(),
                          AnyMemberHasInitPerUnion, [&](const FieldDecl *F) {
-                           if (!FieldsToInit.count(F))
+                           if (!FieldsToInit.contains(F))
                              return;
                            // Don't suggest fixes for enums because we don't
                            // know a good default. Don't suggest fixes for
diff --git a/clang-tools-extra/clang-tidy/google/UpgradeGoogletestCaseCheck.cpp b/clang-tools-extra/clang-tidy/google/UpgradeGoogletestCaseCheck.cpp
index 274b8afa98bd6..c9b48e922ea57 100644
--- a/clang-tools-extra/clang-tidy/google/UpgradeGoogletestCaseCheck.cpp
+++ b/clang-tools-extra/clang-tidy/google/UpgradeGoogletestCaseCheck.cpp
@@ -308,7 +308,7 @@ void UpgradeGoogletestCaseCheck::check(const MatchFinder::MatchResult &Result) {
     }
 
     if (IsInInstantiation) {
-      if (MatchedTemplateLocations.count(ReplacementRange.getBegin()) == 0) {
+      if (!MatchedTemplateLocations.contains(ReplacementRange.getBegin())) {
         // For each location matched in a template instantiation, we check if
         // the location can also be found in `MatchedTemplateLocations`. If it
         // is not found, that means the expression did not create a match
diff --git a/clang-tools-extra/clang-tidy/modernize/AvoidBindCheck.cpp b/clang-tools-extra/clang-tidy/modernize/AvoidBindCheck.cpp
index c9477327742d7..aa7836bcbf169 100644
--- a/clang-tools-extra/clang-tidy/modernize/AvoidBindCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/AvoidBindCheck.cpp
@@ -585,7 +585,7 @@ static bool emitCapture(llvm::StringSet<> &CaptureSet, StringRef Delimiter,
     return false;
 
   // This capture has already been emitted.
-  if (CaptureSet.count(Identifier) != 0)
+  if (CaptureSet.contains(Identifier))
     return false;
 
   Stream << Delimiter;
diff --git a/clang-tools-extra/clang-tidy/modernize/DeprecatedHeadersCheck.cpp b/clang-tools-extra/clang-tidy/modernize/DeprecatedHeadersCheck.cpp
index 35a062382ea3c..47a3ef987ebcf 100644
--- a/clang-tools-extra/clang-tidy/modernize/DeprecatedHeadersCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/DeprecatedHeadersCheck.cpp
@@ -202,7 +202,7 @@ void IncludeModernizePPCallbacks::InclusionDirective(
       It != CStyledHeaderToCxx.end()) {
     IncludesToBeProcessed.emplace_back(IncludeMarker{
         It->second, FileName, FilenameRange.getAsRange(), DiagLoc});
-  } else if (DeleteHeaders.count(FileName) != 0) {
+  } else if (DeleteHeaders.contains(FileName)) {
     IncludesToBeProcessed.emplace_back(
         // NOLINTNEXTLINE(modernize-use-emplace) - false-positive
         IncludeMarker{std::string{}, FileName,
diff --git a/clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp b/clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp
index 6c6c626ec4fed..3ce7b12f92f6b 100644
--- a/clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp
@@ -925,7 +925,7 @@ bool LoopConvertCheck::isConvertible(ASTContext *Context,
   // do any further updates on this iteration.
   if (areDiagsSelfContained())
     TUInfo = std::make_unique<TUTrackingInfo>();
-  else if (TUInfo->getReplacedVars().count(Loop))
+  else if (TUInfo->getReplacedVars().contains(Loop))
     return false;
 
   // Check that we have exactly one index variable and at most one end variable.
diff --git a/clang-tools-extra/clang-tidy/performance/TypePromotionInMathFnCheck.cpp b/clang-tools-extra/clang-tidy/performance/TypePromotionInMathFnCheck.cpp
index 869830aaf9d66..29f9146e47786 100644
--- a/clang-tools-extra/clang-tidy/performance/TypePromotionInMathFnCheck.cpp
+++ b/clang-tools-extra/clang-tidy/performance/TypePromotionInMathFnCheck.cpp
@@ -166,7 +166,7 @@ void TypePromotionInMathFnCheck::check(const MatchFinder::MatchResult &Result) {
       "log1p",     "log2",       "logb",      "lrint",  "lround",   "nearbyint",
       "nextafter", "nexttoward", "remainder", "remquo", "rint",     "round",
       "scalbln",   "scalbn",     "tgamma",    "trunc"};
-  bool StdFnRequiresCpp11 = Cpp11OnlyFns.count(OldFnName);
+  bool StdFnRequiresCpp11 = Cpp11OnlyFns.contains(OldFnName);
 
   std::string NewFnName;
   bool FnInCmath = false;
diff --git a/clang-tools-extra/clang-tidy/utils/ExprSequence.cpp b/clang-tools-extra/clang-tidy/utils/ExprSequence.cpp
index 91736cf5e2f9a..fcbb5ecc7152d 100644
--- a/clang-tools-extra/clang-tidy/utils/ExprSequence.cpp
+++ b/clang-tools-extra/clang-tidy/utils/ExprSequence.cpp
@@ -258,7 +258,7 @@ const Stmt *ExprSequence::getSequenceSuccessor(const Stmt *S) const {
 }
 
 const Stmt *ExprSequence::resolveSyntheticStmt(const Stmt *S) const {
-  if (SyntheticStmtSourceMap.count(S))
+  if (SyntheticStmtSourceMap.contains(S))
     return SyntheticStmtSourceMap.lookup(S);
   return S;
 }
@@ -274,7 +274,7 @@ StmtToBlockMap::StmtToBlockMap(const CFG *TheCFG, ASTContext *TheContext)
 }
 
 const CFGBlock *StmtToBlockMap::blockContainingStmt(const Stmt *S) const {
-  while (!Map.count(S)) {
+  while (!Map.contains(S)) {
     SmallVector<const Stmt *, 1> Parents = getParentStmts(S, Context);
     if (Parents.empty())
       return nullptr;
diff --git a/clang-tools-extra/clang-tidy/utils/FileExtensionsUtils.cpp b/clang-tools-extra/clang-tidy/utils/FileExtensionsUtils.cpp
index e8844281e0309..b40bba6d1f3ab 100644
--- a/clang-tools-extra/clang-tidy/utils/FileExtensionsUtils.cpp
+++ b/clang-tools-extra/clang-tidy/utils/FileExtensionsUtils.cpp
@@ -58,7 +58,7 @@ getFileExtension(StringRef FileName, const FileExtensionsSet &FileExtensions) {
   if (Extension.empty())
     return std::nullopt;
   // Skip "." prefix.
-  if (!FileExtensions.count(Extension.substr(1)))
+  if (!FileExtensions.contains(Extension.substr(1)))
     return std::nullopt;
   return Extension;
 }
diff --git a/clang-tools-extra/clang-tidy/utils/NamespaceAliaser.cpp b/clang-tools-extra/clang-tidy/utils/NamespaceAliaser.cpp
index 22cf23fb2446e..f5949bab8f243 100644
--- a/clang-tools-extra/clang-tidy/utils/NamespaceAliaser.cpp
+++ b/clang-tools-extra/clang-tidy/utils/NamespaceAliaser.cpp
@@ -34,7 +34,7 @@ NamespaceAliaser::createAlias(ASTContext &Context, const Stmt &Statement,
   if (!Function || !Function->hasBody())
     return std::nullopt;
 
-  if (AddedAliases[Function].count(Namespace.str()) != 0)
+  if (AddedAliases[Function].contains(Namespace.str()))
     return std::nullopt;
 
   // FIXME: Doesn't consider the order of declarations.
@@ -84,7 +84,7 @@ std::string NamespaceAliaser::getNamespaceName(ASTContext &Context,
   const auto *Function = getSurroundingFunction(Context, Statement);
   auto FunctionAliases = AddedAliases.find(Function);
   if (FunctionAliases != AddedAliases.end()) {
-    if (FunctionAliases->second.count(Namespace) != 0) {
+    if (FunctionAliases->second.contains(Namespace)) {
       return FunctionAliases->second.find(Namespace)->getValue();
     }
   }

@llvmbot
Copy link
Member

llvmbot commented Sep 5, 2025

@llvm/pr-subscribers-clang-tools-extra

Author: None (flovent)

Changes

Closes #156157


Full diff: https://github.com/llvm/llvm-project/pull/157123.diff

16 Files Affected:

  • (modified) clang-tools-extra/clang-tidy/.clang-tidy (-1)
  • (modified) clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp (+1-1)
  • (modified) clang-tools-extra/clang-tidy/NoLintDirectiveHandler.cpp (+1-1)
  • (modified) clang-tools-extra/clang-tidy/abseil/UpgradeDurationConversionsCheck.cpp (+1-1)
  • (modified) clang-tools-extra/clang-tidy/bugprone/SignalHandlerCheck.cpp (+1-1)
  • (modified) clang-tools-extra/clang-tidy/bugprone/SwappedArgumentsCheck.cpp (+1-1)
  • (modified) clang-tools-extra/clang-tidy/bugprone/UseAfterMoveCheck.cpp (+2-2)
  • (modified) clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp (+2-2)
  • (modified) clang-tools-extra/clang-tidy/google/UpgradeGoogletestCaseCheck.cpp (+1-1)
  • (modified) clang-tools-extra/clang-tidy/modernize/AvoidBindCheck.cpp (+1-1)
  • (modified) clang-tools-extra/clang-tidy/modernize/DeprecatedHeadersCheck.cpp (+1-1)
  • (modified) clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp (+1-1)
  • (modified) clang-tools-extra/clang-tidy/performance/TypePromotionInMathFnCheck.cpp (+1-1)
  • (modified) clang-tools-extra/clang-tidy/utils/ExprSequence.cpp (+2-2)
  • (modified) clang-tools-extra/clang-tidy/utils/FileExtensionsUtils.cpp (+1-1)
  • (modified) clang-tools-extra/clang-tidy/utils/NamespaceAliaser.cpp (+2-2)
diff --git a/clang-tools-extra/clang-tidy/.clang-tidy b/clang-tools-extra/clang-tidy/.clang-tidy
index 0e33364442e76..6bb526c50ff71 100644
--- a/clang-tools-extra/clang-tidy/.clang-tidy
+++ b/clang-tools-extra/clang-tidy/.clang-tidy
@@ -22,7 +22,6 @@ Checks: >
   readability-*,
   -readability-avoid-nested-conditional-operator,
   -readability-braces-around-statements,
-  -readability-container-contains,
   -readability-convert-member-functions-to-static,
   -readability-else-after-return,
   -readability-function-cognitive-complexity,
diff --git a/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp b/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp
index 5e705f720c86e..487e5e299d132 100644
--- a/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp
+++ b/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp
@@ -35,7 +35,7 @@ class ExpandModularHeadersPPCallbacks::FileRecorder {
                          const SrcMgr::ContentCache &ContentCache,
                          llvm::vfs::InMemoryFileSystem &InMemoryFs) {
     // Return if we are not interested in the contents of this file.
-    if (!FilesToRecord.count(File))
+    if (!FilesToRecord.contains(File))
       return;
 
     // FIXME: Why is this happening? We might be losing contents here.
diff --git a/clang-tools-extra/clang-tidy/NoLintDirectiveHandler.cpp b/clang-tools-extra/clang-tidy/NoLintDirectiveHandler.cpp
index ed03b456f4954..a8c978901b551 100644
--- a/clang-tools-extra/clang-tidy/NoLintDirectiveHandler.cpp
+++ b/clang-tools-extra/clang-tidy/NoLintDirectiveHandler.cpp
@@ -349,7 +349,7 @@ bool NoLintDirectiveHandler::Impl::diagHasNoLint(
     return false;
 
   // Do we have cached NOLINT block locations for this file?
-  if (Cache.count(*FileName) == 0)
+  if (!Cache.contains(*FileName))
     // Warning: heavy operation - need to read entire file.
     generateCache(SrcMgr, *FileName, File, *Buffer, NoLintErrors);
 
diff --git a/clang-tools-extra/clang-tidy/abseil/UpgradeDurationConversionsCheck.cpp b/clang-tools-extra/clang-tidy/abseil/UpgradeDurationConversionsCheck.cpp
index 8e27e8e3e0c2b..b2eddf67edb3f 100644
--- a/clang-tools-extra/clang-tidy/abseil/UpgradeDurationConversionsCheck.cpp
+++ b/clang-tools-extra/clang-tidy/abseil/UpgradeDurationConversionsCheck.cpp
@@ -126,7 +126,7 @@ void UpgradeDurationConversionsCheck::check(
 
   if (!match(isInTemplateInstantiation(), *OuterExpr, *Result.Context)
            .empty()) {
-    if (MatchedTemplateLocations.count(Loc) == 0) {
+    if (!MatchedTemplateLocations.contains(Loc)) {
       // For each location matched in a template instantiation, we check if the
       // location can also be found in `MatchedTemplateLocations`. If it is not
       // found, that means the expression did not create a match without the
diff --git a/clang-tools-extra/clang-tidy/bugprone/SignalHandlerCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/SignalHandlerCheck.cpp
index d5cbb847eea98..fa38f5e07f832 100644
--- a/clang-tools-extra/clang-tidy/bugprone/SignalHandlerCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/SignalHandlerCheck.cpp
@@ -525,7 +525,7 @@ bool SignalHandlerCheck::isStandardFunctionAsyncSafe(
   if (!FD->isInStdNamespace() && !FD->isGlobal())
     return false;
 
-  if (ConformingFunctions.count(II->getName()))
+  if (ConformingFunctions.contains(II->getName()))
     return true;
 
   return false;
diff --git a/clang-tools-extra/clang-tidy/bugprone/SwappedArgumentsCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/SwappedArgumentsCheck.cpp
index 8989444dde130..7fdb67e9a7cd9 100644
--- a/clang-tools-extra/clang-tidy/bugprone/SwappedArgumentsCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/SwappedArgumentsCheck.cpp
@@ -91,7 +91,7 @@ void SwappedArgumentsCheck::check(const MatchFinder::MatchResult &Result) {
 
     // Only need to check RHS, as LHS has already been covered. We don't want to
     // emit two warnings for a single argument.
-    if (UsedArgs.count(RHS))
+    if (UsedArgs.contains(RHS))
       continue;
 
     const auto *LHSCast = dyn_cast<ImplicitCastExpr>(ignoreNoOpCasts(LHS));
diff --git a/clang-tools-extra/clang-tidy/bugprone/UseAfterMoveCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/UseAfterMoveCheck.cpp
index 1bcacf96a4129..f9906ebf6ea26 100644
--- a/clang-tools-extra/clang-tidy/bugprone/UseAfterMoveCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/UseAfterMoveCheck.cpp
@@ -148,7 +148,7 @@ UseAfterMoveFinder::find(Stmt *CodeBlock, const Expr *MovingCall,
 std::optional<UseAfterMove>
 UseAfterMoveFinder::findInternal(const CFGBlock *Block, const Expr *MovingCall,
                                  const ValueDecl *MovedVariable) {
-  if (Visited.count(Block))
+  if (Visited.contains(Block))
     return std::nullopt;
 
   // Mark the block as visited (except if this is the block containing the
@@ -232,7 +232,7 @@ void UseAfterMoveFinder::getUsesAndReinits(
   // All references to the variable that aren't reinitializations are uses.
   Uses->clear();
   for (const DeclRefExpr *DeclRef : DeclRefs) {
-    if (!ReinitDeclRefs.count(DeclRef))
+    if (!ReinitDeclRefs.contains(DeclRef))
       Uses->push_back(DeclRef);
   }
 
diff --git a/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp b/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
index e6e79f0f0342a..a79c5281d6054 100644
--- a/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
+++ b/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
@@ -99,7 +99,7 @@ toCommaSeparatedString(const R &OrderedDecls,
                        const SmallPtrSetImpl<const T *> &DeclsToInit) {
   SmallVector<StringRef, 16> Names;
   for (const T *Decl : OrderedDecls) {
-    if (DeclsToInit.count(Decl))
+    if (DeclsToInit.contains(Decl))
       Names.emplace_back(getName(Decl));
   }
   return llvm::join(Names.begin(), Names.end(), ", ");
@@ -501,7 +501,7 @@ void ProTypeMemberInitCheck::checkMissingMemberInitializer(
   AnyMemberHasInitPerUnion = false;
   forEachFieldWithFilter(ClassDecl, ClassDecl.fields(),
                          AnyMemberHasInitPerUnion, [&](const FieldDecl *F) {
-                           if (!FieldsToInit.count(F))
+                           if (!FieldsToInit.contains(F))
                              return;
                            // Don't suggest fixes for enums because we don't
                            // know a good default. Don't suggest fixes for
diff --git a/clang-tools-extra/clang-tidy/google/UpgradeGoogletestCaseCheck.cpp b/clang-tools-extra/clang-tidy/google/UpgradeGoogletestCaseCheck.cpp
index 274b8afa98bd6..c9b48e922ea57 100644
--- a/clang-tools-extra/clang-tidy/google/UpgradeGoogletestCaseCheck.cpp
+++ b/clang-tools-extra/clang-tidy/google/UpgradeGoogletestCaseCheck.cpp
@@ -308,7 +308,7 @@ void UpgradeGoogletestCaseCheck::check(const MatchFinder::MatchResult &Result) {
     }
 
     if (IsInInstantiation) {
-      if (MatchedTemplateLocations.count(ReplacementRange.getBegin()) == 0) {
+      if (!MatchedTemplateLocations.contains(ReplacementRange.getBegin())) {
         // For each location matched in a template instantiation, we check if
         // the location can also be found in `MatchedTemplateLocations`. If it
         // is not found, that means the expression did not create a match
diff --git a/clang-tools-extra/clang-tidy/modernize/AvoidBindCheck.cpp b/clang-tools-extra/clang-tidy/modernize/AvoidBindCheck.cpp
index c9477327742d7..aa7836bcbf169 100644
--- a/clang-tools-extra/clang-tidy/modernize/AvoidBindCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/AvoidBindCheck.cpp
@@ -585,7 +585,7 @@ static bool emitCapture(llvm::StringSet<> &CaptureSet, StringRef Delimiter,
     return false;
 
   // This capture has already been emitted.
-  if (CaptureSet.count(Identifier) != 0)
+  if (CaptureSet.contains(Identifier))
     return false;
 
   Stream << Delimiter;
diff --git a/clang-tools-extra/clang-tidy/modernize/DeprecatedHeadersCheck.cpp b/clang-tools-extra/clang-tidy/modernize/DeprecatedHeadersCheck.cpp
index 35a062382ea3c..47a3ef987ebcf 100644
--- a/clang-tools-extra/clang-tidy/modernize/DeprecatedHeadersCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/DeprecatedHeadersCheck.cpp
@@ -202,7 +202,7 @@ void IncludeModernizePPCallbacks::InclusionDirective(
       It != CStyledHeaderToCxx.end()) {
     IncludesToBeProcessed.emplace_back(IncludeMarker{
         It->second, FileName, FilenameRange.getAsRange(), DiagLoc});
-  } else if (DeleteHeaders.count(FileName) != 0) {
+  } else if (DeleteHeaders.contains(FileName)) {
     IncludesToBeProcessed.emplace_back(
         // NOLINTNEXTLINE(modernize-use-emplace) - false-positive
         IncludeMarker{std::string{}, FileName,
diff --git a/clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp b/clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp
index 6c6c626ec4fed..3ce7b12f92f6b 100644
--- a/clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp
@@ -925,7 +925,7 @@ bool LoopConvertCheck::isConvertible(ASTContext *Context,
   // do any further updates on this iteration.
   if (areDiagsSelfContained())
     TUInfo = std::make_unique<TUTrackingInfo>();
-  else if (TUInfo->getReplacedVars().count(Loop))
+  else if (TUInfo->getReplacedVars().contains(Loop))
     return false;
 
   // Check that we have exactly one index variable and at most one end variable.
diff --git a/clang-tools-extra/clang-tidy/performance/TypePromotionInMathFnCheck.cpp b/clang-tools-extra/clang-tidy/performance/TypePromotionInMathFnCheck.cpp
index 869830aaf9d66..29f9146e47786 100644
--- a/clang-tools-extra/clang-tidy/performance/TypePromotionInMathFnCheck.cpp
+++ b/clang-tools-extra/clang-tidy/performance/TypePromotionInMathFnCheck.cpp
@@ -166,7 +166,7 @@ void TypePromotionInMathFnCheck::check(const MatchFinder::MatchResult &Result) {
       "log1p",     "log2",       "logb",      "lrint",  "lround",   "nearbyint",
       "nextafter", "nexttoward", "remainder", "remquo", "rint",     "round",
       "scalbln",   "scalbn",     "tgamma",    "trunc"};
-  bool StdFnRequiresCpp11 = Cpp11OnlyFns.count(OldFnName);
+  bool StdFnRequiresCpp11 = Cpp11OnlyFns.contains(OldFnName);
 
   std::string NewFnName;
   bool FnInCmath = false;
diff --git a/clang-tools-extra/clang-tidy/utils/ExprSequence.cpp b/clang-tools-extra/clang-tidy/utils/ExprSequence.cpp
index 91736cf5e2f9a..fcbb5ecc7152d 100644
--- a/clang-tools-extra/clang-tidy/utils/ExprSequence.cpp
+++ b/clang-tools-extra/clang-tidy/utils/ExprSequence.cpp
@@ -258,7 +258,7 @@ const Stmt *ExprSequence::getSequenceSuccessor(const Stmt *S) const {
 }
 
 const Stmt *ExprSequence::resolveSyntheticStmt(const Stmt *S) const {
-  if (SyntheticStmtSourceMap.count(S))
+  if (SyntheticStmtSourceMap.contains(S))
     return SyntheticStmtSourceMap.lookup(S);
   return S;
 }
@@ -274,7 +274,7 @@ StmtToBlockMap::StmtToBlockMap(const CFG *TheCFG, ASTContext *TheContext)
 }
 
 const CFGBlock *StmtToBlockMap::blockContainingStmt(const Stmt *S) const {
-  while (!Map.count(S)) {
+  while (!Map.contains(S)) {
     SmallVector<const Stmt *, 1> Parents = getParentStmts(S, Context);
     if (Parents.empty())
       return nullptr;
diff --git a/clang-tools-extra/clang-tidy/utils/FileExtensionsUtils.cpp b/clang-tools-extra/clang-tidy/utils/FileExtensionsUtils.cpp
index e8844281e0309..b40bba6d1f3ab 100644
--- a/clang-tools-extra/clang-tidy/utils/FileExtensionsUtils.cpp
+++ b/clang-tools-extra/clang-tidy/utils/FileExtensionsUtils.cpp
@@ -58,7 +58,7 @@ getFileExtension(StringRef FileName, const FileExtensionsSet &FileExtensions) {
   if (Extension.empty())
     return std::nullopt;
   // Skip "." prefix.
-  if (!FileExtensions.count(Extension.substr(1)))
+  if (!FileExtensions.contains(Extension.substr(1)))
     return std::nullopt;
   return Extension;
 }
diff --git a/clang-tools-extra/clang-tidy/utils/NamespaceAliaser.cpp b/clang-tools-extra/clang-tidy/utils/NamespaceAliaser.cpp
index 22cf23fb2446e..f5949bab8f243 100644
--- a/clang-tools-extra/clang-tidy/utils/NamespaceAliaser.cpp
+++ b/clang-tools-extra/clang-tidy/utils/NamespaceAliaser.cpp
@@ -34,7 +34,7 @@ NamespaceAliaser::createAlias(ASTContext &Context, const Stmt &Statement,
   if (!Function || !Function->hasBody())
     return std::nullopt;
 
-  if (AddedAliases[Function].count(Namespace.str()) != 0)
+  if (AddedAliases[Function].contains(Namespace.str()))
     return std::nullopt;
 
   // FIXME: Doesn't consider the order of declarations.
@@ -84,7 +84,7 @@ std::string NamespaceAliaser::getNamespaceName(ASTContext &Context,
   const auto *Function = getSurroundingFunction(Context, Statement);
   auto FunctionAliases = AddedAliases.find(Function);
   if (FunctionAliases != AddedAliases.end()) {
-    if (FunctionAliases->second.count(Namespace) != 0) {
+    if (FunctionAliases->second.contains(Namespace)) {
       return FunctionAliases->second.find(Namespace)->getValue();
     }
   }

Copy link
Contributor

@vbvictor vbvictor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thank you

@nicovank
Copy link
Contributor

nicovank commented Sep 5, 2025

Note that this check currently has false negatives on strings. #109327
#110351 was a first PR trying to tackle this. I was planning to take it over soon but haven't gotten around to it. IMO the type checking in this check should just be removed for simplicity, as in use-starts-ends-with.

@vbvictor
Copy link
Contributor

vbvictor commented Sep 5, 2025

@flovent, I believe you can file a request to grant commit access for LLVM (and become a member) if you wish.
See label:infra:commit-access-request in issues.

@vbvictor
Copy link
Contributor

vbvictor commented Sep 5, 2025

Note that this check currently has false negatives on strings.

I guess this doesn't hold us back from enabling this check given it's a false-negative.

@nicovank
Copy link
Contributor

nicovank commented Sep 5, 2025

If I wasn't clear, yes I completely agree 👍. Ship it. Just commented for reference.

Copy link
Contributor

@carlosgalvezp carlosgalvezp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@flovent
Copy link
Contributor Author

flovent commented Sep 6, 2025

@flovent, I believe you can file a request to grant commit access for LLVM (and become a member) if you wish.
See label:infra:commit-access-request in issues.

Thanks for the tip! i just file one #157214.

@vbvictor
Copy link
Contributor

vbvictor commented Sep 7, 2025

Do you wish to have this merged or wait for your commit approval (it can take 2-3week if unlucky)?

@flovent
Copy link
Contributor Author

flovent commented Sep 8, 2025

Do you wish to have this merged or wait for your commit approval (it can take 2-3week if unlucky)?

I think it's not necessary to wait, please help me merge it, thanks!

@vbvictor vbvictor merged commit 0a9b54b into llvm:main Sep 8, 2025
12 checks passed
@flovent flovent deleted the tidy-enable-readability-container-contains branch September 9, 2025 13:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[clang-tidy] Enable 'readability-container-contains' check in clang-tidy config.

5 participants